package com.hanfengyi.config;

import com.hanfengyi.hrm.constants.RabbitMQConstants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * User: Han
 * Date: 2020/2/27
 * Time: 22:42
 * Description:
 */
@Configuration
public class RabbitMQConfig {

    @Value("${pageStatic.routingKey}")
    String routingKey;
    //交换机
    @Bean
    public Exchange directExchange(){
        return ExchangeBuilder.directExchange(RabbitMQConstants.EXCHANGE_NAME_DIRECT).build();
    }

    //队列
    @Bean
    public Queue pageStaticQueue(){
        return new Queue(RabbitMQConstants.QUEUE_NAME_PAGE_STATIC);
    }
    //绑定队列到交换机
    @Bean
    public Binding smsBinding(){
        return BindingBuilder.bind(pageStaticQueue()).to(directExchange()).with(routingKey).noargs();
    }

}